/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddNewChild.java
 *
 * Created on Aug 11, 2010, 8:36:33 AM
 */

package GUI;

import config.Database_function;
import config.Function;
import config.User_function;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;

/**
 *
 * @author LINHDDGC60016
 */
public class AddNewChild extends javax.swing.JFrame {

    /** Creates new form AddNewChild */
    public AddNewChild() {
        initComponents();
         Function.Windows_centered(this.getWidth(), this.getHeight(), this);
        setComAGroup();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtFName = new javax.swing.JTextField();
        txtAgeGroupID = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtLName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        Male = new javax.swing.JRadioButton();
        Female = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        txtBirthDay = new com.toedter.calendar.JDateChooser();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        txtFatherName = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtMotherName = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtFatherPhone = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtMotherPhone = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtFatherWorkPhone = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtMotherWorkPhone = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtParentEmail = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        txtDoctorName = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtPastIllness = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txtCurrentMedication = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        txtNextOfKinContact = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        Active = new javax.swing.JRadioButton();
        NotActive = new javax.swing.JRadioButton();
        txtRegistrationDate = new com.toedter.calendar.JDateChooser();
        btnAdd = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Add New Child");

        jPanel1.setBackground(new java.awt.Color(227, 239, 255));

        jLabel1.setFont(new java.awt.Font("VNI 27 Bendigo", 0, 36));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Add New Child");

        jPanel2.setBackground(new java.awt.Color(227, 239, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Child Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N

        jLabel3.setText("First Name");

        txtAgeGroupID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" }));
        txtAgeGroupID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtAgeGroupIDActionPerformed(evt);
            }
        });

        jLabel2.setText("Age Group ID");

        jLabel4.setText("Last Name");

        jLabel5.setText("Gender");

        Male.setBackground(new java.awt.Color(227, 239, 255));
        buttonGroup1.add(Male);
        Male.setSelected(true);
        Male.setText("Male");

        Female.setBackground(new java.awt.Color(227, 239, 255));
        buttonGroup1.add(Female);
        Female.setText("Female");

        jLabel6.setText("Birth Day");

        jLabel7.setText("Address");

        txtBirthDay.setDateFormatString("MMMM/dd/yyyy");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtLName)
                            .addComponent(txtFName, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(Male)
                                .addGap(29, 29, 29)
                                .addComponent(Female))
                            .addComponent(txtAgeGroupID, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtBirthDay, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))))
                .addGap(40, 40, 40))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtLName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtAgeGroupID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Female)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(Male)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(txtBirthDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(227, 239, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Parent Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N

        jLabel8.setText("Father Name");

        jLabel9.setText("Mother Name");

        jLabel10.setText("Father Phone");

        jLabel11.setText("Mother Phone");

        jLabel12.setText("Father Work Phone");

        jLabel13.setText("Mother Work Phone");

        jLabel14.setText("Parent Email");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtParentEmail)
                    .addComponent(txtMotherWorkPhone)
                    .addComponent(txtFatherWorkPhone)
                    .addComponent(txtFatherName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                    .addComponent(txtMotherName, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtMotherPhone)
                    .addComponent(txtFatherPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtFatherName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtMotherName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtFatherPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtMotherPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtFatherWorkPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtMotherWorkPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtParentEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(227, 239, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "History Disease", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N

        jLabel15.setText("Doctor Name");

        txtDoctorName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDoctorNameActionPerformed(evt);
            }
        });

        jLabel16.setText("PastIllness");

        jLabel17.setText("Current Medication");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jLabel17))
                .addGap(28, 28, 28)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCurrentMedication, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                    .addComponent(txtDoctorName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                    .addComponent(txtPastIllness, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtDoctorName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txtPastIllness, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txtCurrentMedication, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(52, Short.MAX_VALUE))
        );

        jPanel5.setBackground(new java.awt.Color(227, 239, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Other Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N

        jLabel18.setText("Next Of Kin Contact");

        jLabel19.setText("Registration Date");

        jLabel20.setText("Status");

        Active.setBackground(new java.awt.Color(227, 239, 255));
        buttonGroup2.add(Active);
        Active.setSelected(true);
        Active.setText("Active");

        NotActive.setBackground(new java.awt.Color(227, 239, 255));
        buttonGroup2.add(NotActive);
        NotActive.setText("Not Active");

        txtRegistrationDate.setDateFormatString("MMMM/dd/yyyy");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19)
                    .addComponent(jLabel20))
                .addGap(34, 34, 34)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(Active)
                        .addGap(18, 18, 18)
                        .addComponent(NotActive))
                    .addComponent(txtNextOfKinContact, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                    .addComponent(txtRegistrationDate, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(txtNextOfKinContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtRegistrationDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(Active)
                    .addComponent(NotActive))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/add.png"))); // NOI18N
        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnReset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/reset.png"))); // NOI18N
        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });

        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Exit.png"))); // NOI18N
        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 858, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(290, 290, 290)
                        .addComponent(btnAdd)
                        .addGap(29, 29, 29)
                        .addComponent(btnReset)
                        .addGap(38, 38, 38)
                        .addComponent(btnExit)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExit)
                    .addComponent(btnReset)
                    .addComponent(btnAdd))
                .addGap(59, 59, 59))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void setComAGroup() {
        try {
            ResultSet rs_ag = User_function.get_age_group();
            this.txtAgeGroupID.removeAllItems();
            while (rs_ag.next()) {
                this.txtAgeGroupID.addItem(rs_ag.getString(1));
            }
        } catch (SQLException ex) {
            Logger.getLogger(AddNewChild.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void txtDoctorNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoctorNameActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtDoctorNameActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        Date d = new Date();
        String date = Function.date_converter("yyyy-MM-dd", d);
        String Regis_date = Function.date_converter("yyyy-MM-dd", this.txtRegistrationDate.getDate());
        
        //Check Child First Name
        if(this.txtFName.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this, "Please input First Name");
            txtFName.requestFocus();
            return;
        }
        //Check Child Last Name
        if(this.txtLName.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this, "Please Input Last Name");
            txtLName.requestFocus();
            return;
        }
        //Check Child Birth Day
        if(this.txtBirthDay.getDate()==null)
        {
            JOptionPane.showMessageDialog(this, "Please Input Birth Day");
            txtBirthDay.requestFocus();
            return;
        }
        else{
            
            if(txtBirthDay.getCalendar().getTime().after(d)){
                JOptionPane.showMessageDialog(this,"Birthday Date < today");
                txtBirthDay.setDate(null);
                txtBirthDay.requestFocus();
                return ;
            }
        }
        //Check Child Address
        if(this.txtAddress.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this, "Please Input Address");
            txtAddress.requestFocus();
            return;
        }
        //Check Father Name
        if(this.txtFatherName.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this, "Please Input Father Name");
            txtFatherName.requestFocus();
            return;
        }
        //Check Mother Name
        if(this.txtMotherName.getText().equals(""))
        {
            JOptionPane.showMessageDialog(this, "Please Input Mother Name");
            txtMotherName.requestFocus();
            return;
        }
        //Check Resgistration Date
        if(this.txtRegistrationDate.getDate()==null)
        {
            JOptionPane.showMessageDialog(this, "Please Input Registration Date");
            txtRegistrationDate.requestFocus();
            return;
        }
        else
        {
            if(!Regis_date.equals(date))
            {
              
                JOptionPane.showMessageDialog(this, "Registration Date = today");
                txtRegistrationDate.requestFocus();
                return;
            }
        }
        //Check Parent Email
        String strEmail="\\w+(\\.\\w+)*@\\w+(\\.\\w+)+";
        if(txtParentEmail.getText().length()!=0)
            if(!Pattern.matches(strEmail,txtParentEmail.getText())){
                JOptionPane.showMessageDialog(this,"Email no match!");
                txtParentEmail.requestFocus();
                txtParentEmail.selectAll();
                return;
            }
        //Check Father Phone
        if(!Pattern.matches("^[0-9]+$", this.txtFatherPhone.getText()))
            {
                JOptionPane.showMessageDialog(this, "Contact Number is Number");
                txtFatherPhone.requestFocus();
                return;
            }
        //Check Mother Phone
        if(!Pattern.matches("^[0-9]+$", this.txtMotherPhone.getText()))
            {
                JOptionPane.showMessageDialog(this, "Contact Number is Number");
                txtMotherPhone.requestFocus();
                return;
            }
        //Check Father Work Phone
        if(!Pattern.matches("^[0-9]+$", this.txtFatherWorkPhone.getText()))
            {
                JOptionPane.showMessageDialog(this, "Contact Number is Number");
                txtFatherWorkPhone.requestFocus();
                return;
            }
        //Check Mother Work Phone
        if(!Pattern.matches("^[0-9]+$", this.txtMotherWorkPhone.getText()))
            {
                JOptionPane.showMessageDialog(this, "Contact Number is Number");
                txtMotherWorkPhone.requestFocus();
                return;
            }
        //Add New Child
        Connection cn= Database_function.setConnection();
        PreparedStatement prstm=null;
        String strSql;

        if(cn!=null) {
            try {

                if(Active.isSelected()){
                    strSql="insert tbl_Child values(?,?,?,?,?,?,?,?,?,?,?,?,1,?,?,?,?,?,?)";
                } else{
                    strSql="insert tbl_Child values(?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,?)";
                }
                prstm = cn.prepareStatement(strSql);
                prstm.setInt(1,Integer.parseInt(User_function.get_age_group_id_by_name(txtAgeGroupID.getSelectedItem().toString())));
                prstm.setString(2,txtParentEmail.getText());
                prstm.setString(3,txtLName.getText());
                prstm.setString(4,txtFName.getText());
                if(this.Male.isSelected()) {
                    prstm.setString(5,Male.getText());
                } else
                    prstm.setString(5,Female.getText());
                prstm.setString(6,txtBirthDay.getCalendar().getTime().toLocaleString());
                prstm.setString(7,txtAddress.getText());
                prstm.setString(8,txtCurrentMedication.getText());
                prstm.setString(9,txtPastIllness.getText());
                prstm.setString(10,txtDoctorName.getText());
                prstm.setString(11,txtNextOfKinContact.getText());
                prstm.setString(12,txtRegistrationDate.getCalendar().getTime().toLocaleString());
                prstm.setString(13,txtFatherName.getText());
                prstm.setString(14,txtMotherName.getText());
                prstm.setString(15,txtFatherPhone.getText());
                prstm.setString(16,txtMotherPhone.getText());
                prstm.setString(17,txtMotherWorkPhone.getText());
                prstm.setString(18,txtFatherWorkPhone.getText());
                prstm.executeUpdate();
                JOptionPane.showMessageDialog(this,"Insert successfully!");

                this.txtAddress.setText("");
                this.txtAgeGroupID.setSelectedItem(1);
                this.txtBirthDay.setCalendar(null);
                this.txtCurrentMedication.setText("");
                this.txtDoctorName.setText("");
                this.txtFName.setText("");
                this.txtFatherName.setText("");
                this.txtFatherWorkPhone.setText("");
                this.txtFatherPhone.setText("");
                this.txtLName.setText("");
                this.txtMotherName.setText("");
                this.txtMotherPhone.setText("");
                this.txtMotherWorkPhone.setText("");
                this.txtNextOfKinContact.setText("");
                this.txtParentEmail.setText("");
                this.txtPastIllness.setText("");
                this.txtRegistrationDate.setCalendar(null);
               
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        } else {
            JOptionPane.showMessageDialog(this,"Connnect false");
        }
}//GEN-LAST:event_btnAddActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btnExitActionPerformed

    private void txtAgeGroupIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAgeGroupIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtAgeGroupIDActionPerformed

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed
        // TODO add your handling code here:
        this.txtAddress.setText("");
        this.txtAgeGroupID.setSelectedItem(1);
        this.txtBirthDay.setCalendar(null);
        this.txtCurrentMedication.setText("");
        this.txtDoctorName.setText("");
        this.txtFName.setText("");
        this.txtFatherName.setText("");
        this.txtFatherWorkPhone.setText("");
        this.txtFatherPhone.setText("");
        this.txtLName.setText("");
        this.txtMotherName.setText("");
        this.txtMotherPhone.setText("");
        this.txtMotherWorkPhone.setText("");
        this.txtNextOfKinContact.setText("");
        this.txtParentEmail.setText("");
        this.txtPastIllness.setText("");
        this.txtRegistrationDate.setCalendar(null);

    }//GEN-LAST:event_btnResetActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddNewChild().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton Active;
    private javax.swing.JRadioButton Female;
    private javax.swing.JRadioButton Male;
    private javax.swing.JRadioButton NotActive;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnReset;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JComboBox txtAgeGroupID;
    private com.toedter.calendar.JDateChooser txtBirthDay;
    private javax.swing.JTextField txtCurrentMedication;
    private javax.swing.JTextField txtDoctorName;
    private javax.swing.JTextField txtFName;
    private javax.swing.JTextField txtFatherName;
    private javax.swing.JTextField txtFatherPhone;
    private javax.swing.JTextField txtFatherWorkPhone;
    private javax.swing.JTextField txtLName;
    private javax.swing.JTextField txtMotherName;
    private javax.swing.JTextField txtMotherPhone;
    private javax.swing.JTextField txtMotherWorkPhone;
    private javax.swing.JTextField txtNextOfKinContact;
    private javax.swing.JTextField txtParentEmail;
    private javax.swing.JTextField txtPastIllness;
    private com.toedter.calendar.JDateChooser txtRegistrationDate;
    // End of variables declaration//GEN-END:variables

}
